// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//=
//= require jquery-2.0.3.min
//= require jquery_ujs
//= require skins.min
//= require bootstrap.min
//= require beyond.min
//= require cocoon
//= require turbolinks
//= require_tree .

$(function() {		
	//--Bootstrap Date Picker--
	$('.date-picker').datepicker();
	
	// -- remove link for nested form item fields --
	$("a.remove_fields").click(function(e) {
		e.preventDefault();
		// this debugger should be hit when you click the submit button!
		$(this).closest('tr').remove();

	});
	
	InitiateSideMenu();
});

function InitiateSideMenu() {
	
	var n = $("#sidebar").hasClass("menu-compact");
	$("#sidebar-collapse").on("click", function() {
		$("#sidebar").is(":visible") || $("#sidebar").toggleClass("hide");
		$("#sidebar").toggleClass("menu-compact");
		$(".sidebar-collapse").toggleClass("active");
		n = $("#sidebar").hasClass("menu-compact");
		n && $(".open > .submenu").removeClass("open");
	});
	
	$(".sidebar-menu").on("click", function(t) {
		var i = $(t.target).closest("a"),u,r,f;
		if (i && i.length != 0) {
			if (!i.hasClass("menu-dropdown"))
				return n && i.get(0).parentNode.parentNode == this && ( u = i.find(".menu-text").get(0), t.target != u && !$.contains(u, t.target)) ? !1 :
				void 0;
			if ( r = i.next().get(0), !$(r).is(":visible")) {
				if ( f = $(r.parentNode).closest("ul"), n && f.hasClass("sidebar-menu"))
					return;
				f.find("> .open > .submenu").each(function() {
					this == r || $(this.parentNode).hasClass("active") || $(this).slideUp(200).parent().removeClass("open");
				});
			}
			return n && $(r.parentNode.parentNode).hasClass("sidebar-menu") ? !1 : ($(r).slideToggle(200).parent().toggleClass("open"), !1);
		}
	});
}

